package com.ruoyi.web.controller.bl;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bl.domain.BlDept;
import com.ruoyi.bl.service.IBlDeptService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商户信息Controller
 * 
 * @author ruoyi
 * @date 2024-11-17
 */
@RestController
@RequestMapping("/bl/dept")
public class BlDeptController extends BaseController
{
    @Autowired
    private IBlDeptService blDeptService;

    /**
     * 查询商户信息列表
     */
    @PreAuthorize("@ss.hasPermi('bl:dept:list')")
    @GetMapping("/list")
    public TableDataInfo list(BlDept blDept)
    {
        startPage();
        List<BlDept> list = blDeptService.selectBlDeptList(blDept);
        return getDataTable(list);
    }

    /**
     * 导出商户信息列表
     */
    @PreAuthorize("@ss.hasPermi('bl:dept:export')")
    @Log(title = "商户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlDept blDept)
    {
        List<BlDept> list = blDeptService.selectBlDeptList(blDept);
        ExcelUtil<BlDept> util = new ExcelUtil<BlDept>(BlDept.class);
        util.exportExcel(response, list, "商户信息数据");
    }

    /**
     * 获取商户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('bl:dept:query')")
    @GetMapping(value = "/{deptId}")
    public AjaxResult getInfo(@PathVariable("deptId") Long deptId)
    {
        return success(blDeptService.selectBlDeptByDeptId(deptId));
    }

    /**
     * 新增商户信息
     */
    @PreAuthorize("@ss.hasPermi('bl:dept:add')")
    @Log(title = "商户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlDept blDept)
    {
        return toAjax(blDeptService.insertBlDept(blDept));
    }

    /**
     * 修改商户信息
     */
    @PreAuthorize("@ss.hasPermi('bl:dept:edit')")
    @Log(title = "商户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlDept blDept)
    {
        return toAjax(blDeptService.updateBlDept(blDept));
    }

    /**
     * 删除商户信息
     */
    @PreAuthorize("@ss.hasPermi('bl:dept:remove')")
    @Log(title = "商户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deptIds}")
    public AjaxResult remove(@PathVariable Long[] deptIds)
    {
        return toAjax(blDeptService.deleteBlDeptByDeptIds(deptIds));
    }

    /**
     * 查询商户信息列表
     */
    @PreAuthorize("@ss.hasPermi('bl:dept:list')")
    @GetMapping("/listAll")
    public AjaxResult listAll(BlDept blDept)
    {
        List<BlDept> list = blDeptService.selectBlDeptList(blDept);
        return success(list);
    }
}
